package cn.scm.server.multistage.base;

import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

@Getter
@Setter
public class PageDTO<T> {
	private List<T> rows;
	private long total;
	private long pages;

	private PageDTO(List<T> rows, long total, long pages) {
		this.rows = rows;
		this.total = total;
		this.pages = pages;
	}

	public static <T> PageDTO<T> of(List<T> rows, long total, long pages) {
		return new PageDTO<>(rows, total, pages);
	}

	public <S> PageDTO<S> convert(Function<T, S> convertToNewRow) {
		List<S> retRows = rows.stream().map(convertToNewRow).collect(Collectors.toList());
		return PageDTO.of(retRows, total, pages);
	}
}
